package com.pausa.sgdi.model.helper
{
	import com.pausa.sgdi.model.vo.ComboDTO;
	
	import mx.collections.ArrayCollection;

	public class CatalogosHelper
	{
		private static var _instance : CatalogosHelper;
		
		public static function getInstance():CatalogosHelper{
			if(_instance == null){
				_instance = new CatalogosHelper();
			}			
			return _instance;
		}
		
		public function createCombo(data : ArrayCollection, property : String):Array
		{
			var result : Array = new Array();
			for(var i : int = 0; i<data.length; i++)
			{
				var dto : ComboDTO = new ComboDTO();
				dto.label = data[i].descripcion;
				dto.value = data[i][property];
				result.push(dto);
			}
			return result;
		}
		
		public function getCurrentItemIndex(data : ArrayCollection, value : Number):Number
		{
			var result : Number = 0;
			for each(var comboDTO : ComboDTO in data){
				if(Number(comboDTO.value) == value){
					break;
				}
				result++;
			}
			return result;
		}
	}
}